package zwp.exercise.service.exercisedemo.chapterFour.PracticeAndExercises;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * @Author zwp14
 * @create 2025/11/29 18:19
 * @description 判断生肖 使用switch语句，判断某一年对应的中国生肖
 */
public class SixExerciseDemo {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要查询的年份：");
        int year = scanner.nextInt();



        // 总共有12个生肖，以此制造索引0~11[这里之所以这样是因为要对12取余，不会出现余数为12的情况]
        // 2020年为鼠年，每12年一个轮询，需要做的是2020年 对 12 取余数为 0
        // 想要达到该目的，就需要2020 再减去 4，由此可以得到已下公式
        int remainderIndex = (year - 4) % 12;
        // 避免余数为负数
        if (remainderIndex < 0){
            remainderIndex += 12;
        }
        String zodiac;
        switch (remainderIndex){
            case 0:
                zodiac = "鼠 (Rat)";
                break;
            case 1:
                zodiac = "牛 (Ox)";
                break;
            case 2:
                zodiac = "虎 (Tiger)";
                break;
            case 3:
                zodiac = "兔 (Rabbit)";
                break;
            case 4:
                zodiac = "龙 (Dragon)";
                break;
            case 5:
                zodiac = "蛇 (Snake)";
                break;
            case 6:
                zodiac = "马 (Horse)";
                break;
            case 7:
                zodiac = "羊 (Goat)";
                break;
            case 8:
                zodiac = "猴 (Monkey)";
                break;
            case 9:
                zodiac = "鸡 (Rooster)";
                break;
            case 10:
                zodiac = "狗 (Dog)";
                break;
            case 11:
                zodiac = "猪 (Pig)";
                break;
            default:
                zodiac = "未知";
        }

        System.out.println("查询到你输入的年份" + year + "为" + zodiac + "年！");

        scanner.close();
    }
}
